package com.itheima.kafka.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: 基础代码
 * @description:
 * @author: zhanghz001
 * @create: 2021-05-11 13:56
 **/
@Component
public class ProducerMq {
    @Autowired
    private KafkaTemplate kafkaTemplate;
    
    @Transactional(rollbackFor = RuntimeException.class)
    public void sendTransactionMessage() {
        // 发送消息
        kafkaTemplate.send("itcast", 0, "order", "事务消息方式二 ----> 1");
        kafkaTemplate.send("itcast", 0, "order", "事务消息方式二 ----> 2");
        // 产生异常代码
        // int a = 1 / 0;
        kafkaTemplate.send("itcast", 0, "order", "事务消息方式二 ----> 3");
    }
    
}
